package com.qczl.pme.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qczl.pme.dao.TownMapper;
import com.qczl.pme.pojo.Town;
import com.qczl.pme.service.TownService;

/**
 * 镇信息业务逻辑层实现类
 * @author SongR
 *
 */
@Service
public class TownServiceImpl implements TownService{
	
	@Resource
	TownMapper tDao;

	/**
	 * 实现获取镇信息
	 */
	public List<Town> getAll(Integer start, Integer size, String serach,String sort,String type) throws Exception {
		Map<String,Object> m = new HashMap<String,Object>();
		m.put("start", start);
		m.put("size", size);
		m.put("townname", serach.equals("")?null:serach);
		m.put("townkeyvalue", serach.equals("")?null:serach);
		m.put("type", type);
		List<Town> tList = tDao.selectAll(m);
		return tList;
	}

	/**
	 * 实现获取镇数量
	 */
	public int count(String serach) throws Exception {
		Map<String,Object> m = new HashMap<String,Object>();
		m.put("serach", serach);
		return tDao.count(m);
	}

	/**
	 * 实现获取sort的最大值
	 */
	public Long getMaxSort() throws Exception {
		
		Long sort = tDao.selectMaxSort();
		
		return sort;
	}

	/**
	 * 实现添加镇信息
	 */
	public void saveOrUpdate(Town town) throws Exception {
		if(town.getTownid()!=null){
			
		}else{
			town.setTownid(UUID.randomUUID().toString());
			tDao.insertSelective(town);
		}
	}

}
